import http from '@/utils/request';

/**
 * 用户登录
 * @param {Object} data 登录数据
 * @returns {Promise}
 */
export const login = (data) => {
  return http.post('/auth/login', data);
};

/**
 * 用户注册
 * @param {Object} data 注册数据
 * @returns {Promise}
 */
export const register = (data) => {
  return http.post('/auth/register', data);
};

/**
 * 获取用户信息
 * @returns {Promise}
 */
export const getUserInfo = () => {
  return http.get('/user/info');
};

/**
 * 更新用户信息
 * @param {Object} data 用户信息
 * @returns {Promise}
 */
export const updateUserInfo = (data) => {
  return http.put('/user/info', data);
};

/**
 * 更新用户头像
 * @param {String} filePath 文件路径
 * @returns {Promise}
 */
export const updateAvatar = (filePath) => {
  return http.upload('/user/avatar', filePath, 'avatar');
};

/**
 * 修改密码
 * @param {Object} data 密码数据
 * @returns {Promise}
 */
export const changePassword = (data) => {
  return http.put('/user/password', data);
};

/**
 * 重置密码
 * @param {Object} data 重置数据
 * @returns {Promise}
 */
export const resetPassword = (data) => {
  return http.post('/auth/reset-password', data);
};

/**
 * 验证令牌
 * @returns {Promise}
 */
export const validateToken = () => {
  return http.get('/auth/validate');
};

/**
 * 退出登录
 * @returns {Promise}
 */
export const logout = () => {
  // 前端清除token
  uni.removeStorageSync('token');
  uni.removeStorageSync('userInfo');
  return Promise.resolve();
};